package com.example.zhanghao.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.zhanghao.DTO.AccountDto;
import com.example.zhanghao.Entity.Account;
import com.example.zhanghao.VO.AccountVo;
import com.example.zhanghao.VO.CommonVo;
import com.example.zhanghao.services.impl.AccountServiceImpl;
import com.example.zhanghao.utils.CopyUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController //这是返回接口
@RequestMapping("/account")
public class AccountController {

    private static final Logger LOG = LoggerFactory.getLogger(AccountController.class);

    @Resource
    AccountServiceImpl accountServiceImpl;

     @GetMapping("/list")
     public CommonVo<List<AccountVo>> list(@Valid AccountDto req){
         LambdaQueryWrapper<Account> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(Account::getTypeId, req.getTypeId());

         List<Account> accountLists =  accountServiceImpl.list(queryWrapper);

         CommonVo<List<AccountVo>> accountCommonVo  = new CommonVo<>();
         accountCommonVo.setData(CopyUtil.copyList(accountLists, AccountVo.class));
         return accountCommonVo;
     }
}

